<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use DB;

class WxQiYeController extends Controller
{


    //
    public function index(Request $request)
    {
        $name=$request->name;
        $post_url = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=ea90d329-faeb-4315-bf03-08bc3da74a90";
		$time=date("m-d H:i");
        $data = [
            "msgtype" => "markdown",
            "markdown" => [
            	"content" => "<font color=\"warning\">$name</font><font color=\"comment\">提醒</font>
            	\n
            	\n
            	> 提醒时间：$time",
            	"mentioned_list" => ["@all"]
            ]
        	
        ];
        
  //      {
		//     "msgtype": "text",
		//     "text": {
		//         "content": "广州今日天气：29度，大部分多云，降雨概率：60%",
		//         "mentioned_list":["wangqing","@all"],
		//         "mentioned_mobile_list":["13800001111","@all"]
		//     }
		// }

        $json_data = json_encode($data); //转化成json让微信可以接收
        $res = $this->https_request($post_url, urldecode($json_data)); //请求开始
		dd($res);
		return "ok";
    }

   //curl请求函数，微信都是通过该函数请求
    private function https_request($url, $data = null)
    {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
        if (!empty($data)) {
            curl_setopt($curl, CURLOPT_POST, 1);
            //curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        }
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($curl);
        curl_close($curl);
        return $output;
    }
    
}